namespace 项目一;
class Student
{
    public string name;
    public string id;
    public string gender;
    private int age;
    public int Age
    {
        get =>age;
        set
        {
           if(value<1||value>150)
           {
            age=0;
           }
           else
           {
            age=value;
           }
        }

    }

    public Phone phone;

    public string GetInfo()
    {
        return $"姓名:{name}\n身份证:{id}\n性别:{gender}\n年龄:{age}\n手机号码:{phone.号码}\n手机型号:{phone.型号}\n";
    }

    public Student(string 姓名, string 身份证, string 手机型号, string 手机号码)
    {
        name = 姓名;
        id = 身份证;
        获取身份证信息();
        phone = new Phone(姓名, 手机型号, 手机号码);
    }

    public void 获取身份证信息()
    {
        int 身份证倒数第2位 = id[16];
        gender = 身份证倒数第2位 % 2 == 0 ? "女" : "男";
        DateTime today = DateTime.Now;
        string year = id[6..10];
        string month = id[10..12];
        string day = id[12..14];
        DateTime birthday = DateTime.Parse($"{year}-{month}-{day}");
        Age = today.Year - birthday.Year;

        if (today.Month < birthday.Month) Age--;
        if (today.Month == birthday.Month && today.Day < birthday.Day) Age--;

    }



}